import QtQuick

Item {
    id: root
    property bool running: visible
    property real iconSize: 100
    property color color: "gray"

    //internal
    property real spotSize: iconSize / 10
    property real swingRadius: (iconSize - spotSize) / 2
    property int spotCount: 6
    property real shiftDegree: 12
    property real delayTime: 100
    property real loadingDuration: 2000
    width: iconSize
    height: iconSize

    Rectangle {
        id: centerAnchor
        anchors.centerIn: parent; width: spotSize; height: spotSize
        Repeater {
            model: spotCount
            delegate: Rectangle {
                id: spot
                width: spotSize; height: width; radius: width/2; color: root.color;
                x:0; y:-swingRadius;
                transform: Rotation {
                    id: rotator
                    origin.x: spotSize/2;
                    origin.y: swingRadius + spotSize/2;
                }

                Connections {
                    target: root
                    ignoreUnknownSignals: true
                    function onRunningChanged() {
                        if(root.running)
                            rotator.angle = shiftDegree*index
                        rotAnim.running = root.running
                    }
                }

                SequentialAnimation {
                    id: rotAnim
                    PauseAnimation { duration: delayTime*index }
                    PropertyAnimation{
                        target: rotator; properties: "angle"; duration: loadingDuration; loops: Animation.Infinite
                        easing.type: Easing.InOutCirc
                        from: rotator.angle; to: rotator.angle - 360;
                    }
                }
            }
        }
    }
}

